package com.apollographql.apollo;

import com.apollographql.apollo.api.Operation;
import com.apollographql.apollo.api.Response;
import com.apollographql.apollo.cache.CacheHeaders;
import com.apollographql.apollo.exception.ApolloCanceledException;
import com.apollographql.apollo.exception.ApolloException;
import com.apollographql.apollo.exception.ApolloHttpException;
import com.apollographql.apollo.exception.ApolloNetworkException;
import com.apollographql.apollo.exception.ApolloParseException;
import com.apollographql.apollo.internal.util.Cancelable;

public interface ApolloCall<T> extends Cancelable {

    public interface Builder<T> {
        ApolloCall<T> build();

        Builder<T> cacheHeaders(CacheHeaders cacheHeaders);
    }

    public enum StatusEvent {
        SCHEDULED,
        FETCH_CACHE,
        FETCH_NETWORK,
        COMPLETED
    }

    @Deprecated
    ApolloCall<T> cacheHeaders(CacheHeaders cacheHeaders);

    @Override // com.apollographql.apollo.internal.util.Cancelable
    void cancel();

    @Deprecated
    ApolloCall<T> clone();

    void enqueue(Callback<T> callback);

    Operation operation();

    Builder<T> toBuilder();

    public static abstract class Callback<T> {
        public abstract void onFailure(ApolloException apolloException);

        public abstract void onResponse(Response<T> response);

        public void onStatusEvent(StatusEvent event) {
        }

        public void onHttpError(ApolloHttpException e) {
            onFailure(e);
            okhttp3.Response response = e.rawResponse();
            if (response != null) {
                response.close();
            }
        }

        public void onNetworkError(ApolloNetworkException e) {
            onFailure(e);
        }

        public void onParseError(ApolloParseException e) {
            onFailure(e);
        }

        public void onCanceledError(ApolloCanceledException e) {
            onFailure(e);
        }
    }
}
